
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Installing SpatiaLite &#8212; Django 1.11.22.dev20190603194737 documentation</title>
    <link rel="stylesheet" href="../../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
    <link rel="next" title="GeoDjango Model API" href="../model-api.html" />
    <link rel="prev" title="Installing PostGIS" href="postgis.html" />



 
<script type="text/javascript" src="../../../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../../index.html">Django 1.11.22.dev20190603194737 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="postgis.html" title="Installing PostGIS">previous</a>
     |
    <a href="../../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="../model-api.html" title="GeoDjango Model API">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-gis-install-spatialite">
            
  <div class="section" id="s-installing-spatialite">
<span id="installing-spatialite"></span><h1>Installing SpatiaLite<a class="headerlink" href="#installing-spatialite" title="Permalink to this headline">¶</a></h1>
<p><a class="reference external" href="https://www.gaia-gis.it/fossil/libspatialite">SpatiaLite</a> adds spatial support to SQLite, turning it into a full-featured
spatial database.</p>
<p>First, check if you can install SpatiaLite from system packages or binaries.</p>
<p>For example, on Debian-based distributions, try to install the
<code class="docutils literal notranslate"><span class="pre">spatialite-bin</span></code> package. For distributions that package SpatiaLite 4.2+,
install <code class="docutils literal notranslate"><span class="pre">libsqlite3-mod-spatialite</span></code>.</p>
<p>For macOS, follow the <a class="reference internal" href="#spatialite-macos"><span class="std std-ref">instructions below</span></a>.</p>
<p>For Windows, you may find binaries on the <a class="reference external" href="https://www.gaia-gis.it/gaia-sins/">Gaia-SINS</a> home page.</p>
<p>In any case, you should always be able to <a class="reference internal" href="#spatialite-source"><span class="std std-ref">install from source</span></a>.</p>
<div class="admonition-spatialite-library-path-setting-required-for-spatialite-4-2 admonition">
<p class="first admonition-title"><code class="docutils literal notranslate"><span class="pre">SPATIALITE_LIBRARY_PATH</span></code> setting required for SpatiaLite 4.2+</p>
<p>If you’re using SpatiaLite 4.2+, you must put this in your settings:</p>
<div class="last highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">SPATIALITE_LIBRARY_PATH</span> <span class="o">=</span> <span class="s1">&#39;mod_spatialite&#39;</span>
</pre></div>
</div>
</div>
<div class="section" id="s-installing-from-source">
<span id="s-spatialite-source"></span><span id="installing-from-source"></span><span id="spatialite-source"></span><h2>Installing from source<a class="headerlink" href="#installing-from-source" title="Permalink to this headline">¶</a></h2>
<p><a class="reference internal" href="geolibs.html"><span class="doc">GEOS and PROJ.4</span></a> should be installed
prior to building SpatiaLite.</p>
<div class="section" id="s-sqlite">
<span id="sqlite"></span><h3>SQLite<a class="headerlink" href="#sqlite" title="Permalink to this headline">¶</a></h3>
<p>Check first if SQLite is compiled with the <a class="reference external" href="https://www.sqlite.org/rtree.html">R*Tree module</a>. Run the sqlite3
command line interface and enter the following query:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sqlite</span><span class="o">&gt;</span> <span class="n">CREATE</span> <span class="n">VIRTUAL</span> <span class="n">TABLE</span> <span class="n">testrtree</span> <span class="n">USING</span> <span class="n">rtree</span><span class="p">(</span><span class="nb">id</span><span class="p">,</span><span class="n">minX</span><span class="p">,</span><span class="n">maxX</span><span class="p">,</span><span class="n">minY</span><span class="p">,</span><span class="n">maxY</span><span class="p">);</span>
</pre></div>
</div>
<p>If you obtain an error, you will have to recompile SQLite from source. Otherwise,
just skip this section.</p>
<p>To install from sources, download the latest amalgamation source archive from
the <a class="reference external" href="https://www.sqlite.org/download.html">SQLite download page</a>, and extract:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ wget https://sqlite.org/sqlite-amalgamation-3.6.23.1.tar.gz
$ tar xzf sqlite-amalgamation-3.6.23.1.tar.gz
$ cd sqlite-3.6.23.1
</pre></div>
</div>
<p>Next, run the <code class="docutils literal notranslate"><span class="pre">configure</span></code> script – however the <code class="docutils literal notranslate"><span class="pre">CFLAGS</span></code> environment variable
needs to be customized so that SQLite knows to build the R*Tree module:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ CFLAGS=&quot;-DSQLITE_ENABLE_RTREE=1&quot; ./configure
$ make
$ sudo make install
$ cd ..
</pre></div>
</div>
</div>
<div class="section" id="s-spatialite-library-libspatialite">
<span id="s-spatialitebuild"></span><span id="spatialite-library-libspatialite"></span><span id="spatialitebuild"></span><h3>SpatiaLite library (<code class="docutils literal notranslate"><span class="pre">libspatialite</span></code>)<a class="headerlink" href="#spatialite-library-libspatialite" title="Permalink to this headline">¶</a></h3>
<p>Get the latest SpatiaLite library source bundle from the
<a class="reference external" href="http://www.gaia-gis.it/gaia-sins/libspatialite-sources/">download page</a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ wget https://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-4.1.0.tar.gz
$ tar xaf libspatialite-4.1.0.tar.gz
$ cd libspatialite-4.1.0
$ ./configure
$ make
$ sudo make install
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>For macOS users building from source, the SpatiaLite library <em>and</em> tools
need to have their <code class="docutils literal notranslate"><span class="pre">target</span></code> configured:</p>
<div class="last highlight-default notranslate"><div class="highlight"><pre><span></span>$ ./configure --target=macosx
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="s-macos-specific-instructions">
<span id="s-spatialite-macos"></span><span id="macos-specific-instructions"></span><span id="spatialite-macos"></span><h2>macOS-specific instructions<a class="headerlink" href="#macos-specific-instructions" title="Permalink to this headline">¶</a></h2>
<p>To install the SpatiaLite library and tools, macOS users can choose between
<a class="reference internal" href="index.html#kyngchaos"><span class="std std-ref">KyngChaos packages</span></a> and <a class="reference external" href="https://brew.sh/">Homebrew</a>.</p>
<div class="section" id="s-kyngchaos">
<span id="kyngchaos"></span><h3>KyngChaos<a class="headerlink" href="#kyngchaos" title="Permalink to this headline">¶</a></h3>
<p>First, follow the instructions in the <a class="reference internal" href="index.html#kyngchaos"><span class="std std-ref">KyngChaos packages</span></a> section.</p>
<p>When creating a SpatiaLite database, the <code class="docutils literal notranslate"><span class="pre">spatialite</span></code> program is required.
However, instead of attempting to compile the SpatiaLite tools from source,
download the <a class="reference external" href="https://www.gaia-gis.it/spatialite-2.3.1/binaries.html">SpatiaLite Binaries</a> for macOS, and install <code class="docutils literal notranslate"><span class="pre">spatialite</span></code> in a
location available in your <code class="docutils literal notranslate"><span class="pre">PATH</span></code>.  For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ curl -O https://www.gaia-gis.it/spatialite/spatialite-tools-osx-x86-2.3.1.tar.gz
$ tar xzf spatialite-tools-osx-x86-2.3.1.tar.gz
$ cd spatialite-tools-osx-x86-2.3.1/bin
$ sudo cp spatialite /Library/Frameworks/SQLite3.framework/Programs
</pre></div>
</div>
<p>Finally, for GeoDjango to be able to find the KyngChaos SpatiaLite library,
add the following to your <code class="docutils literal notranslate"><span class="pre">settings.py</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">SPATIALITE_LIBRARY_PATH</span><span class="o">=</span><span class="s1">&#39;/Library/Frameworks/SQLite3.framework/SQLite3&#39;</span>
</pre></div>
</div>
</div>
<div class="section" id="s-homebrew">
<span id="homebrew"></span><h3>Homebrew<a class="headerlink" href="#homebrew" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="https://brew.sh/">Homebrew</a> handles all the SpatiaLite related packages on your behalf,
including SQLite3, SpatiaLite, PROJ, and GEOS. Install them like this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ brew update
$ brew install spatialite-tools
$ brew install gdal
</pre></div>
</div>
<p>Finally, for GeoDjango to be able to find the SpatiaLite library, add the
following to your <code class="docutils literal notranslate"><span class="pre">settings.py</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">SPATIALITE_LIBRARY_PATH</span><span class="o">=</span><span class="s1">&#39;/usr/local/lib/mod_spatialite.dylib&#39;</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Installing SpatiaLite</a><ul>
<li><a class="reference internal" href="#installing-from-source">Installing from source</a><ul>
<li><a class="reference internal" href="#sqlite">SQLite</a></li>
<li><a class="reference internal" href="#spatialite-library-libspatialite">SpatiaLite library (<code class="docutils literal notranslate"><span class="pre">libspatialite</span></code>)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#macos-specific-instructions">macOS-specific instructions</a><ul>
<li><a class="reference internal" href="#kyngchaos">KyngChaos</a></li>
<li><a class="reference internal" href="#homebrew">Homebrew</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="postgis.html"
                        title="previous chapter">Installing PostGIS</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="../model-api.html"
                        title="next chapter">GeoDjango Model API</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../../_sources/ref/contrib/gis/install/spatialite.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Jun 03, 2019</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="postgis.html" title="Installing PostGIS">previous</a>
     |
    <a href="../../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="../model-api.html" title="GeoDjango Model API">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>